function redirect(path){
	window.location = getCompletePath(path);
}

function getService(url, params, onSuccess, onError) {
	$.ajax({
		type: "GET",
		url: getCompletePath(url),
		data: params
	}).done(function (msg) {
        if (onSuccess) {
        	onSuccess(msg);
        }
    }).fail(function (msg) {
        if (onError) {
        	onError(msg);
        } else {
        	error_handler(msg);
        }
    });
}

function postService(url, params, onSuccess, onError) {
    $.ajax({
        type: "POST",
        url: getCompletePath(url),
        contentType: 'application/json; charset=utf-8',
        data: params
    }).done(function (msg) {
        if (onSuccess) {
        	onSuccess(msg);
        }
    }).fail(function (msg) {
        if (onError) {
        	onError(msg);
        } else {
        	error_handler(msg);
        }
    });
}

function error_handler(exception) {
	//alert("Tuvimos un error, disculpe las molestias");
}

function getCompletePath(path) {
	if(ctx == "") {
		return "/" + path;
	}
	
	return ctx + "/" + path;
}

function getImagePath(pathController, imageName, type){
	type = type || 'none';
	return getCompletePath(pathController) + '?fileName=' + imageName + '&type=' + type;
}

function getParameterByName(name) {
    name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
        results = regex.exec(location.search);
    return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}

function getHash() {
	return window.location.hash.substring(window.location.hash.indexOf('#')+1);
}

function getHashValue(key) {
	var hashes = getHash().split("&");
	for(var i = 0; i < hashes.length; i++) {
		var hash = hashes[i].split("=");
		if(hash[0] == key) {
			return hash[1];
		}
	}
	
	return undefined;
}

function changeHashValue(key, value) {
	if(getHashValue(key)) {
		var newHash = "";
		var hashes = getHash().split("&");
		for(var i = 0; i < hashes.length; i++) {
			if(i != 0) {
				newHash += "&";
			}
			
			var hash = hashes[i].split("=");
			if(hash[0] == key) {
				newHash += hash[0] + "=" + value;
			} else {
				newHash += hashes[i];
			}
		}
		
		window.location.hash = newHash;
	} else if(getHash().length == 0) {
		window.location.hash = key + "=" + value;
	} else {
		window.location.hash += "&" + key + "=" + value;
	}
}

String.prototype.replaceAll = function(str1, str2, ignore) {
    return this.replace(new RegExp(str1.replace(/([\/\,\!\\\^\$\{\}\[\]\(\)\.\*\+\?\|\<\>\-\&])/g,"\\$&"),(ignore?"gi":"g")),(typeof(str2)=="string")?str2.replace(/\$/g,"$$$$"):str2);
};